<template>
  <div class="list">
    <Title></Title>
    <div class="home_list">
      <div class="inner" style="padding: 0;">
        <div class="list">
          <div class="list_noe" v-if="searcharr.length===0">没有搜索到商品</div>
          <div class="list_box" v-else>
            <div class="list_item" v-for="(item,index) in searcharr" :key="index"  @click="detailurl(item)">
              <div class="item_img">
                <img :src="[item.goods_img]">
              </div>
              <div class="list_info">
                <div class="list_name txt-cut3">{{item.goods_name}}</div>
                <div class="list_price">￥{{item.goods_price}}</div>
              </div>
            </div>
          </div>
        </div>

      </div>
    </div>
    <el-drawer
      :visible.sync="drawer"
      size="100%">
          <img :src="[copydata]" alt="" srcset="">
    </el-drawer>
  </div>
</template>

<script>
import {
  searchapi, pddcopyapi, noOwningClick
} from "../../api/http.js"
  import Title from "../../components/title.vue"
  export default {
    name: 'list',
    components: {
      Title
    },
    data() {
      return {
        searcharr: [],
        drawer: false,
        copydata:[]
      }
    },
    created() {
      this.getsearch()
    },
    methods: {
     async getsearch(){
        const res = await searchapi({
          page:1,
          page_size:10,
          keyword:this.$route.query.search
        })
        console.log(res.data);
        if (res.data.code==200) {
          this.searcharr =res.data.data
        } else if(res.data.code==0){
          this.searcharr = []
        }else{
          this.searcharr = []
        }
      },
      detailurl(item) {
        console.log(item);
        if (item.is_owning === 1) {
          console.log(item);
          if (item.goods_type===1) {
            noOwningClick();
            window.open(item.jd_path)
          } else if(item.goods_type === 2){
            noOwningClick();
            window.open(item.tb_path)
          }else{
            this.$router.push({
              path: '/detail',
              query: {
                goodsid: item.goods_id
              }
            })
          }
        } else {
          noOwningClick();
          this.copydata=""
          this._getpddcopy({
            mp_page:item.page_path
          })
          console.log(item.page_path);
          this.drawer = !this.drawer
        }
      },
     async _getpddcopy({mp_page}){
        const res = await pddcopyapi({mp_page})
        if (res.data.code==200) {
          console.log(res.data.data.qrcode);
        this.copydata = res.data.data.qrcode
        } else{
          this.copydata=""
        }
      }
    }
  }
</script>

<style lang="less" scoped>
  @import url(../../../static/index.less);
  .el-drawer__wrapper .el-drawer{
    background: rgba(0, 0, 0, 0.6);
  }
  .el-drawer__close-btn{
    font-size: 40px !important;
    color: #fff;
  }
  .el-drawer__body{
    display: flex;
    justify-content: center;
    align-items: center;
    img{
      width: 200px;
      height: 200px;
    }
  }
  .list_noe {
    width: 100%;
    height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
  }
</style>
